package cn.gene.timeyan.ums.webapi.ums.controller;

import cn.gene.timeyan.common.restful.JsonResult;
import cn.gene.timeyan.pojo.ums.vo.FollowVO;
import cn.gene.timeyan.ums.service.IAttentionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 关注    前端控制器*
 *
 * @author LWG
 * @date 2022/7/23 11:07
 * @since 1.0.0@gene.cn
 */
@RestController
@RequestMapping("/ums/Attention")
@Api(tags="关注模块")
public class

AttentionController {
    @Autowired
    private IAttentionService attentionService;
    @ApiOperation("获取关注列表")
    @PostMapping("/list")
    public JsonResult<List<FollowVO>> followList(Long userId){
        return attentionService.followList(userId);
    }
    @ApiOperation("关注")
    @ApiImplicitParams({

            @ApiImplicitParam(value = "用户ID",name = "userId",dataType = "Long",
                    required = true),
            @ApiImplicitParam(value = "关注ID",name = "followUserId",dataType = "Long",
                    required = true),
    })
    @PostMapping("/attention")
    public JsonResult attention(
            @RequestParam(value = "userId",defaultValue = "1L")Long userId,
            @RequestParam(value = "followUserId",defaultValue = "2L") Long followUserId
    ){
        if(userId==null||followUserId==null) {
            return JsonResult.ok("数据不能为空");
        }
        attentionService.addAttention(userId, followUserId);
        return JsonResult.ok("关注成功");
    }
    @ApiOperation("取消关注")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户ID",name = "userId",dataType = "Long",
                    required = true),
            @ApiImplicitParam(value = "关注ID",name = "followUserId",dataType = "Long",
                    required = true),
    })

    @PostMapping("/notAttention")
    public JsonResult notAttention(
            @RequestParam(value = "userId",defaultValue = "1L")Long userId,
            @RequestParam(value = "followUserId",defaultValue = "2L") Long followUserId
    ){
        if(userId==null||followUserId==null) {
            return JsonResult.ok("数据不能为空");
        }
        attentionService.deleteAttention(userId, followUserId);
        return JsonResult.ok("取消关注成功");
    }

}
